using System;
using System.Web.UI;
using facebook;
using System.Web.Configuration;

namespace facebook.web
{
	public class CanvasFBMLBasePage : Page
	{
        private readonly API _api = new API();
        private bool _requireLogin = false;

        public string ApiKey { get; set; }

        public string Secret { get; set; }
        public string suffix
        {
            get { return WebConfigurationManager.AppSettings["Suffix"]; }
        }
        public string callback
        {
            get { return WebConfigurationManager.AppSettings["Callback"]; }
        }

		/// <summary>
		/// Determines whether or not the page being displayed requires that the user be logged into
		/// the application before viewing the page. If this is true, and the user is not logged in,
		/// they will be redirected to the login/allow access page. The default is false.
		/// 
		/// This property must be set before the Page_Init method is called on this class. To set it in
		/// the page that inherits from this class, set it in that page's Page_Init method.
		/// </summary>
        public bool RequireLogin
        {
            get { return _requireLogin; }
            set { _requireLogin = value; }
        }

        public API API
        {
            get { return _api; }
        }

		protected void Page_Init(object sender, EventArgs e)
		{
			// ApplicationKey and Secret are acquired when you sign up for 
            var apiKey = WebConfigurationManager.AppSettings["APIKey"];
            var secret = WebConfigurationManager.AppSettings["Secret"];
            _api.ApplicationKey = apiKey;
			_api.Secret = secret;

			BasePageHelper.LoadFBMLPage(_api, _requireLogin, Request, Response);
		}
	}
}